package com.hotel.utils;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;

public final class JsonUtil {
    /**
     * 默认实例
     */
    public static final ObjectMapper INSTANCE;
    /**
     * PascalCase实例
     */
    public static final ObjectMapper PASCAL_CASE_INSTANCE;

    public static final ObjectMapper DB_EXTENSION_INSTANCE;

    static {
        INSTANCE = new ObjectMapper();
        INSTANCE.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        PASCAL_CASE_INSTANCE = new ObjectMapper();
        PASCAL_CASE_INSTANCE
            .setPropertyNamingStrategy(new PropertyNamingStrategy.PropertyNamingStrategyBase() {
                /**  */
                private static final long serialVersionUID = 1766624727188140566L;

                @Override
                public String translate(final String propertyName) {
                    // "camelCase" to "PascalCase"
                    return StringUtils.capitalize(propertyName);
                }
            });

        DB_EXTENSION_INSTANCE = new ObjectMapper();
        DB_EXTENSION_INSTANCE.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        DB_EXTENSION_INSTANCE.configure(SerializationFeature.FAIL_ON_SELF_REFERENCES, false);
        DB_EXTENSION_INSTANCE.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
        DB_EXTENSION_INSTANCE.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        DB_EXTENSION_INSTANCE.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
        DB_EXTENSION_INSTANCE.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    }
    
    
    
}